﻿var createUrl;
var basePath="${base_path}";
window.onload = function(){
createUrl=basePath+"issue/visitor/${key}";
var templater = '<div id="tool-view"  style=" position: fixed;top: 25px;right:7px;padding:0px 0px 0px 0px;border:3px solid #0e820b;width:43px;height: 38px;"  >'+
    '<img id="img" src="'+basePath+'resources/layout/img/green.gif" title="如果您有意见，请反馈给我们！" alt="如果您有意见，请反馈给我们！" onmouseout="out(this)" onmousemove="over(this)"/></div>';
var node = document.createElement("div");
node.innerHTML=templater;
document.body.appendChild(node);
var obj = document.getElementById('tool-view');
rDrag.init(obj);
}
function over(img){
img.src=basePath+"resources/layout/img/orange.gif";
}
function out(img){
img.src=basePath+"resources/layout/img/green.gif";
}
function createIssue( createUrl){
window.open(createUrl);
}

var rDrag = {
o:null,
beforeLeft:null,
beforeTop:null,
divWidth:43,
divHeight:38,
tempX:null,
tempY:null,
init:function(o){
o.onmousedown = this.start;
},
start:function(e){
var o;
e.preventDefault && e.preventDefault();
rDrag.o = o = this;
o.x = e.clientX - rDrag.o.offsetLeft;
o.y = e.clientY - rDrag.o.offsetTop;
rDrag.beforeLeft=rDrag.o.offsetLeft;
rDrag.beforeTop=rDrag.o.offsetTop;
document.onmousemove = rDrag.move;
document.onmouseup = rDrag.end;
},
move:function(e){
var oLeft,oTop;
oLeft = e.clientX - rDrag.o.x;
oTop = e.clientY - rDrag.o.y;
rDrag.o.style.left = oLeft + 'px';
rDrag.o.style.top = oTop + 'px';
},
end:function(e){
var tempX=rDrag.o.offsetLeft;
var tempY=rDrag.o.offsetTop;
if(rDrag.o.offsetLeft<0){
tempX=0;
if(rDrag.o.offsetTop<0){
tempY=0;
}else if((rDrag.o.offsetTop+rDrag.divHeight)> (window.innerHeight-5)){
tempY=window.innerHeight-5-rDrag.divHeight;
}
}
else if((rDrag.o.offsetLeft+rDrag.divWidth)>window.innerWidth-5){
tempX=window.innerWidth-5-rDrag.divWidth;
if(rDrag.o.offsetTop<0){
tempY=0;
}else if((rDrag.o.offsetTop+rDrag.divHeight)> (window.innerHeight-5)){
tempY=window.innerHeight-5-rDrag.divHeight;
}
}else{
//tempX=rDrag.o.offsetLeft;
if(rDrag.o.offsetTop<0){
tempY=0;
}else if((rDrag.o.offsetTop+rDrag.divHeight)> (window.innerHeight-5)){
tempY=window.innerHeight-5-rDrag.divHeight;
}
}
rDrag.o.style.left = tempX + 'px';
rDrag.o.style.top = tempY + 'px';
if((rDrag.beforeLeft==rDrag.o.offsetLeft)&&(rDrag.beforeTop==rDrag.o.offsetTop)){
createIssue(createUrl);
}
rDrag.o =rDrag.beforeLeft =rDrag.beforeTop =document.onmousemove = document.onmouseup = null;
}
};